#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more 
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership. 
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with 
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion


using System;
using System.Drawing;
using System.Drawing.Drawing2D;


namespace IPSim.GUI.Devices
{
    /// <author>Edward Smit</author>
    public abstract class BaseLinkDevice : BaseDevice
    {
        #region Members

        protected ConnectorDevice connector1;
        protected ConnectorDevice connector2;

        #endregion

        #region Methods

        internal BaseLinkDevice(ConnectorDevice c1, ConnectorDevice c2): base()
        {
            connector1 = c1;
            connector1.ConnectLink(this);
            connector2 = c2;
            connector2.ConnectLink(this);

            c1.ConnectLink(this);
            c2.ConnectLink(this);            
        }

        internal abstract override void Draw(Graphics g);

        internal abstract void CalcLink();

        #endregion

        #region Properties

        public ConnectorDevice Connector1
        {
            get
            {
                return connector1;
            }
            set
            {
                if (value == null)
                    return;

                connector1.DisconnectLink(this);
                connector1 = value;
                connector1.ConnectLink(this);
                OnConnectorChanged(new EventArgs());
            }
        }

        public ConnectorDevice Connector2
        {
            get
            {
                return connector2;
            }
            set
            {
                if (value == null)
                    return;

                connector2.DisconnectLink(this);
                connector2 = value;
                connector2.ConnectLink(this);
                OnConnectorChanged(new EventArgs());
            }
        }

        public abstract override Point Location
        {
            get;
        }

        public abstract override Size Size
        {
            get;
        }

        public abstract Point StartPoint
        {
            get;
        }

        public abstract Point EndPoint
        {
            get;
        }

        #endregion

        #region Events

        public event EventHandler ConnectorChanged;

        protected virtual void OnConnectorChanged(EventArgs e)
        {
            if (ConnectorChanged != null)
                ConnectorChanged(this, e);
        }

        #endregion

    }
}
